package cn.xiongxf.basic.service.impl;

import cn.xiongxf.basic.constant.FastDfsConstants;
import cn.xiongxf.basic.service.IBaiduAiAuditService;
import cn.xiongxf.basic.util.BaiduAiUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class BaiduAiAuditServiceImpl implements IBaiduAiAuditService {

    @Override
    public Boolean textAudit(String auditText) {
        return BaiduAiUtils.textCensor(auditText);
    }

    /*
     *  注意:resources的格式：
     *  /group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk161.png,/group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk162.png
     *  需要判断是否为空，只有一张怎么处理，有多张怎么处理
     *  需要统一加前缀：http://123.207.27.208
     */
    @Override
    public Boolean imageAudit(String resources) {
        Boolean imageBoo = true;
        // 图片途径是否为空
        if (!StringUtils.isEmpty(resources)) {
            String[] arr = resources.split(",");  // 只有一张图片也可以用split
            for (String resource : arr) {
                // 审核每张图片
                String httpResource = FastDfsConstants.DFS_SERVER_URL_PREFIX + resource;
                imageBoo = BaiduAiUtils.imgCensor(httpResource);
                if (!imageBoo) {
                    // 审核失败
                    return imageBoo;
                }
            }
        }
        return imageBoo;
    }
}